<template>
  <page-layout :title="title">
    <a-card :bordered="false">
      <detail-list title="个人信息">
        <detail-list-item term="登录帐号">{{userinfo.username}}</detail-list-item>
        <detail-list-item term="用户姓名">{{userinfo.realname}}</detail-list-item>
        <detail-list-item term="联系电话">{{userinfo.phone}}</detail-list-item>
        <detail-list-item term="部门编码">{{userinfo.orgCode}}</detail-list-item>
        <detail-list-item term="部门名称">{{userinfo.bm}}</detail-list-item>
        <detail-list-item term="创建时间">{{userinfo.createTime}}</detail-list-item>
      </detail-list>
      <a-divider style="margin-bottom: 32px"/>

      <div class="title">登录日志</div>
<!--      <s-table-->
<!--        style="margin-bottom: 24px" -->
<!--        :columns="goodsColumns" -->
<!--        :data="loadGoodsData">-->

<!--      </s-table>-->
      <a-table :columns="goodsColumns" :data-source="GoodsData">
        <a slot="name" slot-scope="text">{{ text }}</a>
      </a-table>

      <div class="title">操作日志</div>
<!--      <s-table-->
<!--        style="margin-bottom: 24px" -->
<!--        :columns="scheduleColumns" -->
<!--        :data="loadScheduleData">-->

<!--        <template-->
<!--          slot="status"-->
<!--          slot-scope="status">-->
<!--          <a-badge :status="status" :text="status | statusFilter"/>-->
<!--        </template>-->

<!--      </s-table>-->
      <a-table :columns="scheduleColumns" :data-source="scheduleData">
        <a slot="name" slot-scope="text">{{ text }}</a>
      </a-table>
    </a-card>
  </page-layout>
</template>

<script>
  import PageLayout from '@comp/page/PageLayout.vue'
  import STable from '@comp/table'
  import DetailList from '@comp/tools/DetailList.vue'
  import ABadge from "ant-design-vue/es/badge/Badge"
  const DetailListItem = DetailList.Item
  import store from '@/store'
  import { filterObj } from '@/utils/util'
  import { getAction } from '@api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  export default {
    mixins:[JeecgListMixin],
    components: {
      PageLayout,
      ABadge,
      DetailList,
      DetailListItem,
      STable
    },
    data () {
      return {
        GoodsData : [],
        scheduleData : [],
        userinfo:{},
        queryParam: {},
        goodsColumns : [
          {
            title: '日志内容',
            dataIndex: 'logContent',
            key: 'logContent'
          },
          {
            title: '操作人ID',
            dataIndex: 'userid',
            key: 'userid'
          },
          {
            title: '操作人名称',
            dataIndex: 'username',
            key: 'username'
          },
          {
            title: 'IP地址',
            dataIndex: 'ip',
            key: 'ip',
            align: 'right'
          },
          {
            title: '操作时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center'
          },
        ],
        scheduleColumns: [
          {
            title: '日志内容',
            dataIndex: 'logContent',
            key: 'logContent'
          },
          {
            title: '操作人ID',
            dataIndex: 'userid',
            key: 'userid'
          },
          {
            title: '操作人名称',
            dataIndex: 'username',
            key: 'username'
          },
          {
            title: 'IP地址',
            dataIndex: 'ip',
            key: 'ip',
            align: 'right'
          },
          {
            title: '操作时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center'
          },
        ],

      }
    },
    filters: {
      statusFilter(status) {
        const statusMap = {
          'processing': '进行中',
          'success': '完成',
          'failed': '失败'
        }
        return statusMap[status]
      }
    },
    created() {
      this.userinfo = store.getters.userInfo;
      this.loadGoodsData();
    },
    computed: {

      title () {
        return this.$route.meta.title
      }
    },
    methods:{
      loadGoodsData(){
        var param = Object.assign({}, this.queryParam,this.isorter);
        param.field = this.getQueryField();
        param.pageNo = 1;
        param.pageSize = 10;
        delete param.createTimeRange; // 时间参数不传递后台

        getAction("/sys/log/listUserLoginLog",param).then((res)=>{
          if(res.success){
            this.GoodsData = res.result.records;
          }else{
            this.GoodsData = [];
          }
        })

        getAction("/sys/log/listUserOprLog",param).then((res)=>{
          if(res.success){
            this.scheduleData = res.result.records;
          }else{
            this.scheduleData =[];
          }
        })
      },
      getQueryField() {
        //TODO 字段权限控制
        var str = "id,";
        this.goodsColumns.forEach(function (value) {
          str += "," + value.dataIndex;
        });
        return str;
      },
      loadScheduleData(){

      },
    },

  }
</script>

<style lang="less" scoped>
  .title {
    color: rgba(0,0,0,.85);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 16px;
  }
</style>